package com.zhuanzhuan.hero.user.helper;

import com.bj58.youpin.common.utils.json.JsonUtils;
import com.bj58.zhuanzhuan.merchant.contract.IMerchantAllService;
import com.bj58.zhuanzhuan.merchant.entity.MerchantAll;
import com.zhuanzhuan.hunter.log.interceptor.LogContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName ZzMerchantHelper
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/28 15:45
 */
@Component
@Slf4j
public class ZzMerchantHelper {

    @Resource
    private IMerchantAllService merchantAllService;

    private final int BID = 1810000;

    /**
     * 查询所有生效中的转转已验机2.0商户
     *
     * @param uids
     * @return java.util.List<com.bj58.zhuanzhuan.merchant.entity.MerchantAll>
     * @author  hanjunjun
     * @date 2024/6/28
     **/
    public List<MerchantAll> getEffectiveByUidsAndBid(List<Long> uids) {
        uids = uids.stream().distinct().collect(Collectors.toList());
        log.info("getMerchantAllByUidsAndBid param={}", JsonUtils.toJsonWithoutNull(uids));
        List<MerchantAll> resultList =
            merchantAllService.getMerchantallListByUIdsAndBid(LogContext.getLogStr(), uids, BID);
        log.info("getMerchantAllByUidsAndBid result={}", JsonUtils.toJsonWithoutNull(resultList));

        //筛选出有效的
        return resultList.stream()
            .filter(merchant -> MerchantAll.MerchantStatus.SUCCESS.getStatus().byteValue() == merchant.getStatus())
            .collect(Collectors.toList());
    }
}
